#ifndef PICKBUSINESS_H
#define PICKBUSINESS_H

#include <BMPackSim_global.h>
#include <IBMPackSim.h>
#include <corelib\kernel\qobject.h>
#include <corelib\kernel\qtimer.h>
#include <corelib\thread\qthread.h>
#include <corelib\tools\qdatetime.h>
#include <corelib\thread\qmutex.h>
#include <corelib\thread\qwaitcondition.h>



class QGraphicsScene;

namespace PackSim
{
	class ItemCreator;
	class Conveyor;
	class EllipseItem;
	


	class PICKBUSINESS_EXPORT BMPackSim :public QObject, public QThread, public IBMPackSim
	{

		Q_OBJECT

	public:
		BMPackSim(QObject* parent);
		~BMPackSim();

	protected:
		
		void run();
		

	signals:

		void mainTimerTimeOut();
		void invokeUpdateAll(int deltaTime);

	private slots:

		void onMainTimerTimeOut();
		void onInvokeUpdateAll(int deltaTime);



	// these methods are public on the interface
	private:
		
		void startSimulation();
		void stopSimulation();
		
		void createConveyor(const QString& aCnvName);
		void destroyConveyor();
		Conveyor* getConveyor(const QString& aCnvName);

		EllipseItem* createEllipseItem(Conveyor *aConveyor);
		void destroyEllipseItem(EllipseItem *aEllipseItem);

		ItemCreator* createItemCreator(const QString& aItemCreatorName);
		void destroyItemCreator();
		ItemCreator* getItemCreator(const QString& aItemCreatorName);

		QMap<QString, Conveyor*> conveyorMap() const;
		QMap<QString, ItemCreator*> itemCreatorMap() const;
		

		QGraphicsScene* scene();

	private:

		QTimer mMainTimer;
		
		QMap<QString, Conveyor*> mConveyorMap;
		QMap<QString, ItemCreator*> mItemCreatorMap;


		QGraphicsScene* mGraphicsScene;

		bool updatedAll;

		bool mSimulating;
		QTime mSimulationTime;
		QMutex mutex;
		QWaitCondition mWaitContition;







	};
}

#endif // PICKBUSINESS_H
